package com.cyzy.controller;

import com.cyzy.dao.DistributionApplicationDao;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Campusdistriapply;
import com.cyzy.pojo.CourseParent;
import com.cyzy.pojo.DistributorApp;
import com.cyzy.pojo.User;
import com.cyzy.service.DistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/distribution")
public class DistributionController {
    @Autowired
    private DistributionService distributionService;

    @GetMapping("/selectExit")
    public Result exitUser(DistributorApp distributorApp) {
        DistributorApp exit = distributionService.exitUser(distributorApp);
        return Result.ok().data("exit", exit);
    }

    @GetMapping("/selectSchoolStatus")
    public Result exitCampusApp(Campusdistriapply campusdistriapply) {
        Campusdistriapply exit = distributionService.exitCampusApp(campusdistriapply);
        System.out.println(exit + "23213123123123213213123");
        return Result.ok().data("exit", exit);
    }

    @GetMapping("/selectInfoU")
    public Result getUser(@RequestParam Long userId) {
        User user = distributionService.getUser(userId);
        return Result.ok().data("info", user);
    }

    @GetMapping("/selectInfoP")
    public Result getParent(@RequestParam Long parentId) {
        CourseParent parent = distributionService.getParent(parentId);
        return Result.ok().data("info", parent);
    }

    @GetMapping("/selectAllInfoU")
    public Result selectUser(@RequestParam Long userId) {
        DistributionApplicationDao user = distributionService.selectUser(userId);
        return Result.ok().data("info", user);
    }

    @GetMapping("/selectAllInfoP")
    public Result selectParent(@RequestParam Long parentId) {
        DistributionApplicationDao parent = distributionService.selectParent(parentId);
        return Result.ok().data("info", parent);
    }

    @PostMapping("/DistributorApp")
    public Result insertDistributionApp(@RequestBody DistributorApp distributorApp){
        DistributorApp exitUser = distributionService.exitUser(distributorApp);
        if (exitUser != null) {
            return Result.error().message("账号已存在");
        }else {
            distributionService.insertDistributionApp(distributorApp);
            return Result.ok().message("申请成功");
        }
    }

    @PostMapping("/schoolDistributionApp")
    public Result schoolDistributionApp(@RequestBody Campusdistriapply campusdistriapply){
        Campusdistriapply exitCampusApp = distributionService.exitCampusApp(campusdistriapply);
        if (exitCampusApp != null) {
            return Result.error().message("账号已存在");
        }else {
            distributionService.schoolDistributionApp(campusdistriapply);
            return Result.ok().message("申请成功");
        }
    }
}
